gdkwindow: avoid updating background pattern if it matches previous
authorChristian Hergert <christian@hergert.me>
Tue, 16 Jun 2015 21:40:09 +0000 (14:40 -0700)
committerChristian Hergert <christian@hergert.me>
Tue, 16 Jun 2015 21:40:09 +0000 (14:40 -0700)
Background patterns are often updated when style changes. In many cases,
the new pattern will match the previous. We can optimize out the
invalidation that will occur upon resetting the same pattern.

gdk/gdkwindow.c

index faa848c243b85276e1e4ae63e5bb40714a3dbf7d..f1971cb7d22c5a701ac23c4d295be987722406e3 100644 (file)
@@ -5977,10 +5977,25 @@ gdk_window_set_background_rgba (GdkWindow     *window,
                                 const GdkRGBA *rgba)
 {
   cairo_pattern_t *pattern;
+  GdkRGBA prev_rgba;
 
   g_return_if_fail (GDK_IS_WINDOW (window));
   g_return_if_fail (rgba != NULL);
 
+  /*
+   * If the new RGBA matches the previous pattern, ignore the change so that
+   * we do not invalidate the window contents.
+   */
+  if ((window->background != NULL) &&
+      (cairo_pattern_get_type (window->background) == CAIRO_PATTERN_TYPE_SOLID) &&
+      (cairo_pattern_get_rgba (window->background,
+                               &prev_rgba.red,
+                               &prev_rgba.green,
+                               &prev_rgba.blue,
+                               &prev_rgba.alpha) == CAIRO_STATUS_SUCCESS) &&
+      gdk_rgba_equal (&prev_rgba, rgba))
+    return;
+
   pattern = cairo_pattern_create_rgba (rgba->red, rgba->green,
                                        rgba->blue, rgba->alpha);